/*
 * Copyright (c) 2009 Enio Perpetuo
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * 		http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 *  
 */
package co.za.gvi.smart;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * This class represents a <code>VCalendar</code> which is a file 
 * format standard for exchanging calendar and schedule information.
 * 
 * @author Enio Perpetuo
 */
public class VCalendar extends SmartMessage {
	
	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd HHmmss");

	private String version = "1.0";
	private String startDateTime;
	private String endDateTime;
	private String description;
	private String summary;
	
	/**
	 * Set the version
	 * @param version the version to set
	 */
	public void setVersion(String version) {
		this.version = version;
	}

	/**
	 * Set the start date time
	 * @param startDateTime the startDateTime to set
	 */
	public void setStartDateTime(Date startDateTime) {
		this.startDateTime = dateFormat.format(startDateTime).replace(' ', 'T');
	}

	/**
	 * Set the end date time
	 * @param endDateTime the endDateTime to set
	 */
	public void setEndDateTime(Date endDateTime) {
		this.endDateTime = dateFormat.format(endDateTime).replace(' ', 'T');
	}

	/**
	 * Set the description
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Set the summary
	 * @param summary the summary to set
	 */
	public void setSummary(String summary) {
		this.summary = summary;
	}

	@Override
	public String toString() {
		this.builder = new StringBuilder();

		builder.append("BEGIN:VCALENDAR");
		builder.append(CRLF);
		append(this.version, "VERSION:");
		builder.append("BEGIN:VEVENT");
		builder.append(CRLF);
		
		append(this.summary, 		"SUMMARY:");
		append(this.description, 	"DESCRIPTION:");
		append(this.startDateTime,	"DTSTART:");
		append(this.endDateTime,	"DTEND:");
		
		builder.append("END:VEVENT");
		builder.append(CRLF);
		builder.append("END:VCALENDAR");
		builder.append(CRLF);
		
		return builder.toString();
	}
}